home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / util4 / forcepns.lha / ForcePens / main.c < prev    next >
C/C++ Source or Header  |  1996-02-06  |  3KB  |  117 lines

  1. /*
  2. **    ForcePens
  3. **
  4. **    Copyright ©1995, 1996 by Daniel Balster
  5. **
  6. */
  7.  
  8. #include <exec/exec.h>
  9. #include <dos/dos.h>
  10. #include <utility/hooks.h>
  11. #include <intuition/intuition.h>
  12.  
  13. #include <proto/dos.h>
  14. #include <proto/exec.h>
  15. #include <proto/intuition.h>
  16. #include <proto/graphics.h>
  17.  
  18. #include <string.h>
  19. #include <stdlib.h>
  20.  
  21. /****************************************************/
  22. //#define DEBUG
  23.  
  24. #ifdef DEBUG
  25. void kprintf(UBYTE *fmt,...);
  26. #define bug kprintf
  27. #define D(X) X
  28. #else
  29. #define D(X)
  30. #endif
  31.  
  32. #define AllocStruct(X)    AllocVec(sizeof(struct X),MEMF_CLEAR|MEMF_PUBLIC)
  33. #define FreeStruct(X)    if (X) FreeVec(X)
  34.  
  35. #define ifnot(expr)    if(!(expr))
  36.  
  37. typedef enum { false=0, true=~(false) } bool;
  38. /****************************************************/
  39.  
  40. /* OpenWorkBench */
  41. #define VEC -0xd2
  42. #define LIB (struct Library*) IntuitionBase
  43.  
  44. extern APTR NewVector;
  45. extern APTR OldVector;
  46.  
  47. extern long __oslibversion = 37L;
  48.  
  49. static char vers[] = "$VER: ForcePens 1.1 (29.1.96) ©1996 Daniel Balster";
  50.  
  51. /* bad style, but works */
  52.  
  53. #define TEMPL    "PEN1/N/A,R1/N/A,G1/N/A,B1/N/A,PEN2/N/A,R2/N/A,G2/N/A,B2/N/A,PEN3/N/A,R3/N/A,G3/N/A,B3/N/A,PEN4/N/A,R4/N/A,G4/N/A,B4/N/A,BORDERMAGIC/N,QUIET/S"
  54.  
  55. struct {
  56.     ULONG *pen1,*r1,*g1,*b1;
  57.     ULONG *pen2,*r2,*g2,*b2;
  58.     ULONG *pen3,*r3,*g3,*b3;
  59.     ULONG *pen4,*r4,*g4,*b4;
  60.     ULONG *bordermagic;
  61.     ULONG quiet;
  62. } args = {0};
  63.  
  64.  
  65. VOID __asm newfunc (register __a0 struct Screen *scr)
  66. {
  67.     struct ViewPort *vp = &(scr->ViewPort);
  68.     struct ColorMap *cm = vp->ColorMap;
  69.  
  70.     if (args.bordermagic) scr->WBorBottom = *args.bordermagic;
  71.  
  72.     if ( *args.pen1 == ObtainPen (cm, *args.pen1, *args.r1, *args.g1, *args.b1, PEN_EXCLUSIVE) )
  73.     if ( *args.pen2 == ObtainPen (cm, *args.pen2, *args.r2, *args.g2, *args.b2, PEN_EXCLUSIVE) )
  74.     if ( *args.pen3 == ObtainPen (cm, *args.pen3, *args.r3, *args.g3, *args.b3, PEN_EXCLUSIVE) )
  75.     if ( *args.pen4 == ObtainPen (cm, *args.pen4, *args.r4, *args.g4, *args.b4, PEN_EXCLUSIVE) )
  76.     {
  77.         SetRGB32 (vp, *args.pen1, (*args.r1<<24)|0xffffff, (*args.g1<<24)|0xffffff, (*args.b1<<24)|0xffffff);
  78.         SetRGB32 (vp, *args.pen2, (*args.r2<<24)|0xffffff, (*args.g2<<24)|0xffffff, (*args.b2<<24)|0xffffff);
  79.         SetRGB32 (vp, *args.pen3, (*args.r3<<24)|0xffffff, (*args.g3<<24)|0xffffff, (*args.b3<<24)|0xffffff);
  80.         SetRGB32 (vp, *args.pen4, (*args.r4<<24)|0xffffff, (*args.g4<<24)|0xffffff, (*args.b4<<24)|0xffffff);
  81.     }
  82. }
  83.  
  84. int main ()
  85. {
  86.     struct RDArgs *rda;
  87.     
  88.     if (rda = ReadArgs(TEMPL,(LONG*)&args,NULL))
  89.     {
  90.         if (!args.quiet) PutStr(
  91. "*** ForcePens 1.1 ***\n"
  92. "Copyright © 1996 by Daniel Balster\n"
  93. "All Rights Reserved.\n");
  94.  
  95.         Disable();
  96.         OldVector = SetFunction (LIB,VEC,(ULONG(*)())&(NewVector));
  97.         CacheClearU();
  98.         Enable();
  99.  
  100.         Wait (SIGBREAKF_CTRL_C);
  101.         
  102.         if (FindPort("SetMan"))
  103.         {
  104.             Disable();
  105.             SetFunction (LIB,VEC,(ULONG(*)())(OldVector));
  106.             CacheClearU();
  107.             Enable();
  108.         }
  109.         else Wait(0);
  110.  
  111.         FreeArgs(rda);
  112.     }
  113.     else PrintFault(IoErr(),0);
  114.  
  115.     return 0;
  116. }
  117.